import { createApp } from 'vue';

const promiseBreaker = () => {
   let resolve, reject;
   let promise = new Promise((s, j) => {
       // eslint-disable-line
       resolve = s;
       reject = j;
       setTimeout(reject, 15 * 1000, "pending time up");
   });
   return Object.assign(promise, { resolve, reject });
};

const wsBus = (window.wsBus = createApp({
 data: {
   timer: null,
   type: null,
   ws: null,
   WS_URL: "",
   connectReady: promiseBreaker(), // 将是可外部决议的promise
   from: 0,
   period: "",
 },

 watch: {},
 methods: {
   // 盘口数据处理 币币
   handerBibiData(data) {
   
   },
   // 盘口数据处理 合约
   handerDataPank(data) {
     
   },

   unzip(b64Data) {
     
   },
   init() {
     console.log('init');
   },
   doClose() {

   },
   async reqKlinHistory(symbol, resolution, from, to) {
     // 请求k线历史数据
     let res = await new Promise((resolve, reject) => {
       this.$once("klineHistoryData", (msg) => {
         resolve(msg);
       });

     });
     return res;
   },
 },
 created() {
   this.init();
   window.MV.$on("currentType", (type) => {
     this.type = type;
   });
 },
}));

export default wsBus;

